package com.linhh.mall.center.web.controller;

import com.github.pagehelper.PageInfo;
import com.linhh.mall.center.api.CollectionService;
import com.linhh.mall.center.common.pojo.Collection;
import com.linhh.mall.center.common.pojo.CollectionStatus;
import com.linhh.mall.center.common.util.HttpResult;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author linhh
 * @Date 2023 03 18 11 57
 **/
@RestController
@RequestMapping("/api")
public class CollectionController {

    @Reference
    private CollectionService collectionService;

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    @GetMapping("/collection/{id}")
    public HttpResult getCollectionById(@PathVariable Long id){
        Collection collection = collectionService.getCollectionById(id);
        return HttpResult.success(collection);
    }


    /**
     * 添加
     * @param collection
     * @return
     */
    @PostMapping("/addCollection")
    public int addCollection(@RequestBody Collection collection){
        return collectionService.addCollection(collection);
    }

    /**
     * 更新藏品信息
     * @param collection
     * @return
     */
    @PutMapping("/updateCollection")
    public int updateCollection(@RequestBody Collection collection){
        collectionService.updateCollection(collection);
        return 1;
    }

    /**
     * 获取藏品列表
     * @param collection
     * @return
     */
    @GetMapping("/getCollectionList")
    public HttpResult getCollectionList(Collection collection){
        List<Collection> collectionList = collectionService.getCollectionList();
        return HttpResult.success(collectionList);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/deleteCollection/{id}")
    public int deleteCollection(@PathVariable Long id){
        collectionService.deleteCollection(id);
        return 1;
    }

    /**
     *  筛选藏品
     * @param number  藏品编码
     * @param name    藏品名称
     * @param status  状态
     * @return
     */
    @GetMapping("/getCollections")
    public List<Collection> getCollections(@RequestParam(required = false) String number,
                                           @RequestParam(required = false) String name,
                                           @RequestParam(required = false) CollectionStatus status){
        List<Collection> collections = collectionService.getCollections(number,name,status);
        return collections;
    }

    @GetMapping("/collection/pageList")
    public HttpResult getPageCollectionInfo(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,@RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        PageInfo<Collection> collectionPageInfo = collectionService.selectPageInfo(pageNum,pageSize);
        return HttpResult.success(collectionPageInfo);
    }

}
